﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Linq;
using System.Xml;
using ArmoryBrowser.Entities;
using System.Net;

namespace ArmoryBrowser
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("introduzca un nombre de servidor y de personaje");
            }
            else
            {
                XDocument doc = LoadCharacter(args[0], args[1]);
                CharacterPage p = new CharacterPage(doc.Root);
            }
            
        }

        private static XDocument LoadCharacter(String realmName, String characterName)
        {
            Uri serverUri = new Uri("http://Armory.wow-europe.com");
            UriBuilder builder = new UriBuilder(serverUri);
            builder.Path = "character-sheet.xml";
            builder.Query = String.Format("r={0}&cn={1}", realmName, characterName);
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(builder.Uri);
            req.UserAgent = "MSIE 7.0";
            WebResponse response = req.GetResponse();
            using (Stream str = response.GetResponseStream())
            {
                using (XmlReader rdr = XmlReader.Create(str))
                {
                    return XDocument.Load(rdr);
                }
            }
        }
    }
}
